package com.rie06.openvoip.client.IHM.home;

import com.rie06.openvoip.client.Client;
import com.rie06.openvoip.client.IHM.communication.CommunicationController;
import com.rie06.openvoip.server.Server;
import com.rie06.openvoip.server.ServerUDP;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.apache.log4j.Logger;

public class InterfaceClient extends JFrame{

    private static final Logger logger = Logger.getLogger(InterfaceClient.class);
    
    private Server server;
    private ServerUDP serverUDP;
    private Client client;
    
    private ListContactPanel listContactPanel;
    private PanelAddContact panelAddContact;
    private CommunicationController communicationController;
    private PanelRequest panelRequest;
    private Map conversationWindowList;    
    private AddContact addContact;
 
    public InterfaceClient(Server server, ServerUDP serverUDP, CommunicationController communicationController){
        
        this.server = server;
        this.communicationController = communicationController; 
        this.communicationController.setInterfaceClient(this);
        
        this.conversationWindowList = new HashMap();

        this.serverUDP = serverUDP;

        this.setBackground(Color.white);
        server.setIhm(this);
        serverUDP.setIhm(this);
        
        addContact = new AddContact(this);
        
        
                // ********************** WINDOW ************************/
		this.setTitle("OpenVOIP - "+server.getServerConfig().getUserName());
		this.setSize(400, 800);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLocationRelativeTo(null);
                this.setResizable(false);
                this.setBackground(Color.white);

                listContactPanel= new ListContactPanel(this,communicationController);

                panelAddContact = new PanelAddContact(this, this.communicationController);
                
                
                JPanel panelBordure = new JPanel();
                panelBordure.setPreferredSize(new Dimension(400, 25));
                panelBordure.setBackground(Color.lightGray);
                JLabel labelListContact = new JLabel(" Liste de contacts");
                JLabel labelSeparator = new JLabel("              ");
                JLabel labelConversationRequest = new JLabel("Demande de conversation");
                
                panelBordure.add(labelListContact);
                panelBordure.add(labelSeparator);
                panelBordure.add(labelConversationRequest);
           
                panelRequest = new PanelRequest(this, communicationController);

		// ********************* DISPLAY *********************/
		BorderLayout styleFenetre = new BorderLayout();
		this.getContentPane().setLayout(styleFenetre);
                this.getContentPane().add(listContactPanel, BorderLayout.WEST);
                this.getContentPane().add(panelRequest, BorderLayout.EAST);
		this.getContentPane().add(panelAddContact, BorderLayout.SOUTH);
                this.getContentPane().add(panelBordure, BorderLayout.NORTH);
		this.setVisible(true);
		// *************************************************/
    }

    public PanelAddContact getPanelAddContact() {
        return panelAddContact;
    }

    
    
    public void setClient(Client client) {
        this.client = client;
    }

    public ListContactPanel getListContact() {
        return listContactPanel;
    }

    public void setListContact(ListContactPanel listContact) {
        this.listContactPanel = listContact;
    }

    public AddContact getAddContact() {
        return addContact;
    }

    public Client getClient() {
        return client;
    }

    public Server getServer() {
        return server;
    }


    public Map getConversationWindowList() {
        return conversationWindowList;
    }


    public PanelRequest getPanelRequest() {
        return panelRequest;
    }

    public CommunicationController getCommunicationController() {
        return communicationController;
    }



    
}
